package com.cusc.module_apply.mvvm.vm;

import android.app.Application;
import android.widget.RadioGroup;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.cusc.lib_api.bean.RespList;
import com.cusc.lib_api.bean.dic.DircBean;
import com.cusc.module_apply.R;
import com.cusc.module_apply.model.ApplyMainModel;
import com.cusc.module_apply.model.ApplyMainModelFactory;
import com.cusc.module_apply.mvvm.model.ApplyMainNetRegister;
import com.tcgroup.phone.base_core.framework.mvvm.viewmodel.BaseRefreshViewModel;
import com.tcgroup.phone.base_core.widget.SmartCheckBoxGridLayout;
import com.tcgroup.phone.base_core.widget.SmartRadioGroup;
import com.tcgroup.phone.base_core.widget.model.SmartEditLinearLayoutModel;
import com.tcgroup.phone.base_core.widget.model.SmartRadioGroupModel;

import java.util.ArrayList;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * 作者: wangfei
 * 创建时期: 2020/3/28.
 * 包名: com.cusc.module_apply.mvvm.vm
 * 类名: OSAndroidMvvm
 */
public class ApplyActMainViewModel extends BaseRefreshViewModel<String, ApplyMainNetRegister> implements SmartRadioGroup.OnCheckedChangeListener, SmartCheckBoxGridLayout.GetCheckBoxIdsListener {

    public ArrayList<ApplyMainModel> tabLayout = new ArrayList<>();
    public ObservableField<SmartEditLinearLayoutModel> ycrModel = new ObservableField<>();
    public ObservableField<SmartEditLinearLayoutModel> yj_ycModel = new ObservableField<>();
    public ObservableField<SmartEditLinearLayoutModel> yj_jsModel = new ObservableField<>();
    public ObservableField<SmartEditLinearLayoutModel> yc_dwModel = new ObservableField<>();
    public ObservableField<ArrayList<SmartRadioGroupModel>> dispatchStatuesModel = new ObservableField<>();
    public ObservableField<ArrayList<SmartRadioGroupModel>> applyStatuesModel = new ObservableField<>();


    public ApplyActMainViewModel(@NonNull Application application, ApplyMainNetRegister netRegister) {
        super(application, netRegister);
        tabLayout.add(ApplyMainModelFactory.getApplyMainModel("未提交", R.drawable.core_glide_default,false));
        tabLayout.add(ApplyMainModelFactory.getApplyMainModel("审批中", R.drawable.core_glide_default,false));
        tabLayout.add(ApplyMainModelFactory.getApplyMainModel("调度中", R.drawable.core_glide_default,false));
        tabLayout.add(ApplyMainModelFactory.getApplyMainModel("已调度", R.drawable.core_glide_default,false));
        ycrModel.set(new SmartEditLinearLayoutModel("用车人:","",
                "请输入您要查询的用车人姓名"));
        yj_ycModel.set(new SmartEditLinearLayoutModel("预计用车时间:","",
                "请选择您要查询的预计用车时间"));
        yj_jsModel.set(new SmartEditLinearLayoutModel("预计结束时间:","",
                "请选择您要查询的预计结束时间"));
        yc_dwModel.set(new SmartEditLinearLayoutModel("用车单位:","",
                "请选择您的用车单位"));
    }


    public void getDictStatues(){
        postShowInitLoadViewEvent(true);

        mNetRegister.getDictToDispatchStatues().subscribe(new Observer<RespList<ArrayList<DircBean>>>() {
            @Override
            public void onSubscribe(Disposable d) {
                accept(d);
            }

            @Override
            public void onNext(RespList<ArrayList<DircBean>> dircBeans) {
                postShowCurrentEvent(true);
                ArrayList<SmartRadioGroupModel> list = new ArrayList<>();
                for(DircBean bean : dircBeans.list){
                    SmartRadioGroupModel model = new SmartRadioGroupModel(bean.getItemName(),bean.getItemValue());
                    list.add(model);
                }
                dispatchStatuesModel.set(list);
            }

            @Override
            public void onError(Throwable e) { }

            @Override
            public void onComplete() { }
        });

        mNetRegister.getDictToApplyStatues().subscribe(new Observer<RespList<ArrayList<DircBean>>>() {
            @Override
            public void onSubscribe(Disposable d) {
                accept(d);
            }
            @Override
            public void onNext(RespList<ArrayList<DircBean>> arrayListRespList) {
                ArrayList<SmartRadioGroupModel> list = new ArrayList<>();
                for(DircBean bean : arrayListRespList.list){
                    SmartRadioGroupModel model = new SmartRadioGroupModel(bean.getItemName(),bean.getItemValue());
                    list.add(model);
                }
                applyStatuesModel.set(list);
            }

            @Override
            public void onError(Throwable e) { }

            @Override
            public void onComplete() { }
        });

    }


    @Override
    public void refreshData() {

    }

    @Override
    public void loadMore() {
    }


    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId, SmartRadioGroupModel model) {

    }

    @Override
    public void getIds(int[] dirs) {
    }
}
